<?php
/**
 *   File functions:
 *   Jail
 *
 *   @name                 : jail.php                            
 *   @copyright            : (C) 2004-2005 Vallheru Team based on Gamers-Fusion ver 2.5
 *   @author               : thindil <thindil@users.sourceforge.net>
 *   @version              : 1.0 rc1
 *   @since                : 14.11.2005
 *
 */

//
//
//       This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// 

$title = "Areszt";
require_once("includes/head.php"); if (!$_GET['ajax']) require_once("includes/head_start.php"); 

/**
* Get the localization for game
*/
require_once("languages/".$player -> lang."/jail.php");

if ($player -> location != 'Altara' && $player -> location != 'Areszt' && $player -> location != 'Ardulith') 
{
    error (ERROR);
}


/**
* If player is in city - show prisoners
*/
if ($player -> location == 'Altara' || $player -> location == 'Ardulith') 
{
    $smarty -> display ('areszt.tpl');

//kasowanie pustych
    $jail2 = $db -> Execute("SELECT * FROM areszt ORDER BY id ASC");
        while (!$jail2 -> EOF) 
        {
            $pname2 = $db -> Execute("SELECT user FROM players WHERE id=".$jail2 -> fields['prisoner']);
		if (!$pname2 -> fields['user']) 
		{
		$db -> Execute("delete from areszt where prisoner=".$jail2 -> fields['prisoner']);
		}
            $jail2 -> MoveNext();

	}
    $jail2 -> Close();

    $jail = $db -> Execute("SELECT * FROM areszt ORDER BY id ASC");

    $number = $jail -> RecordCount();
    $smarty -> assign ("Number", $number);
    if ($number > 0) 
    {
        $arrid = array();
        $arrname = array();
        $arrdate = array();
        $arrverdict = array();
        $arrduration = array();
        $arrjailid = array();
        $arrcost = array();
        $i = 0;
        while (!$jail -> EOF) 
        {
            $pname = $db -> Execute("SELECT user FROM players WHERE id=".$jail -> fields['prisoner']);
            $arrid[$i] = $jail -> fields['prisoner'];
            $arrname[$i] = $pname -> fields['user'];
            $arrdate[$i] = $jail -> fields['data'];
            $arrverdict[$i] = $jail -> fields['verdict'];
            $arrduration[$i] = $jail -> fields['duration'];
            $arrjailid[$i] = $jail -> fields['id'];
            $arrcost[$i] = $jail -> fields['cost'];
            $jail -> MoveNext();
            $i = $i + 1;
        }
        $smarty -> assign(array("Id" => $arrid, 
            "Name" => $arrname, 
            "Date" => $arrdate, 
            "Verdict" => $arrverdict, 
            "Duration" => $arrduration, 
            "Jailid" => $arrjailid, 
            "Cost" => $arrcost,
            "Pname" => P_NAME,
            "Pid" => P_ID,
            "Pdate" => P_DATE,
            "Preason" => P_REASON,
            "Pduration" => P_DURATION,
            "Pcost" => P_COST,
            "Goldcoins" => GOLD_COINS,
            "Jailinfo" => JAIL_INFO));
    }
        else
    {
        $smarty -> assign(array("Noprisoners" => NO_PRISONERS,
            "Jailinfo" => JAIL_INFO));
    }
    $jail -> Close();
}

/**
* If player is in jail - show info about it
*/
if ($player -> location == 'Areszt') 
{
    $prisoner = $db -> Execute("SELECT * FROM areszt WHERE prisoner=".$player -> id);
    $smarty -> assign(array("Date" => $prisoner -> fields['data'], 
        "Verdict" => $prisoner -> fields['verdict'], 
        "Duration" => $prisoner -> fields['duration'], 
        "Cost" => $prisoner -> fields['cost'],
        "Youare" => YOU_ARE,
        "Pdate" => P_DATE,
        "Pduration" => P_DURATION,
        "Preason" => P_REASON,
        "Pcost" => P_COST));
    $prisoner -> Close();
}


/**
* Assign variables to template and display page
*/
$smarty -> assign("Location", $player -> location);
$smarty -> display ('areszt.tpl');

if (!$_GET['ajax']) require_once("includes/foot.php");
?>
